This is a race.
A NullPointerException is raised due to the bug.
More details about this bug are at LOG4J-44032
JIRA page.
This happens at
org.apache.log4j.spi.ThrowableInformation:
The numbers present the global execution sequence.
t1 t2 public String[] getThrowableStrRep() {
1 3 if(rep != null) {
4 return (String[]) rep.clone();
} else {
StringWriter sw = new StringWriter();
...
2 rep = new String[lines.size()];
5 lines.toArray(rep);
}
return rep;
}
a) rep is null when t1 is at 1.
b) t1 executes 2, and rep is initialized.
c) Now context switched, t2 comes to 3 and checks rep which is not null now.
d) t2 comes to 4, returns a not null rep whose elements are null.
e) when the elements of rep are referenced in t2, a NullPointerException is thrown out.
This bug is reproduced under log4j 1.2.15 and JDK 1.6.0_33.
Execute
the following scripts to run the test to reproduce the bug (assume the
location of the log4j test project is log4j_test_home).
Linux:
${log4j_test_home}/scripts/44032.sh
Windows:
%log4j_test_home%\scripts\44032.bat